import os
import uuid
from uuid import uuid4
class Myfile:
    def __init__(self,upload_dir='./static/upload/'):
        self.up_dir = upload_dir

    #根据用户ID创建新的文件夹
    def mk_dir(self,userid):
        path = self.up_dir+str(userid)+'/'
        if not os.path.exists(path):
            os.mkdir(path)
    
    #重命名
    def rename(self,file):
        filename = uuid.uuid4().hex+os.path.splitext(file)[1]
        return filename
    
    #根据用户ID查找指定文件下的所有文件
    def show_file(self,userid):
        files = os.listdir(self.up_dir+str(userid)+'/')
        return files        
    #删除
    def remove_file(self,userid,file):
        path = self.up_dir+str(userid)+'/'+file
        os.remove(path)

myfile = Myfile()
files = myfile.show_file(1)
print(files)
# myfile.rename('123.jpg')